/*
 * GoodsDetailInfoFragment.java
 * business
 *
 * Created by SunDing on 2016/9/28.
 *
 * Copyright (c) 2016年 yidiandao. All rights reserved.
 */

package com.yidiandao.business.ui.goodsdetail.standard;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.OrientationHelper;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yidiandao.business.R;
import com.yidiandao.business.base.BaseFragment;
import com.yidiandao.business.data.bean.Goods;
import com.yidiandao.business.data.response.GoodsDetailResponse;
import com.yidiandao.business.ui.adapter.RecommendGoodsAdapter;
import com.yidiandao.business.ui.widget.view.SpaceItemDecoration;
import com.yidiandao.business.utils.UIUtils;

/**
 * 商品规格
 */
public class GoodsDetailStandardFragment extends BaseFragment
        implements GoodsDetailStandardContract.View {
    GoodsDetailStandardContract.Presenter mPresenter;
    private TextView mTvWeight;
    private TextView mTvBrand;
    private LinearLayout mLlGoodsIntention;
    private RecyclerView mRecyclerView;
    private RecommendGoodsAdapter mAdapter;
    private TextView mTvUnit;

    public static GoodsDetailStandardFragment getInstance() {
        return new GoodsDetailStandardFragment();
    }

    @Override
    public void setPresenter(GoodsDetailStandardContract.Presenter presenter) {
        mPresenter = presenter;
    }

    @Override
    public String getPagerTag() {
        return GoodsDetailStandardFragment.class.getSimpleName();
    }

    @Override
    public void showToast(String text) {
    }

    @Override
    protected void initViews() {

        mTvWeight = (TextView) mRootView.findViewById(R.id.tv_weight);
        mTvBrand = (TextView) mRootView.findViewById(R.id.tv_brand);
        mTvUnit = (TextView) mRootView.findViewById(R.id.tv_unit);

        mLlGoodsIntention = (LinearLayout) mRootView.findViewById(R.id.ll_goods_intention);
        mRecyclerView = (RecyclerView) mRootView.findViewById(R.id.recycler_view);

        LinearLayoutManager layoutManager = new LinearLayoutManager(mActivity);
        //设置布局管理器
        mRecyclerView.setLayoutManager(layoutManager);
        //设置为垂直布局，这也是默认的
        layoutManager.setOrientation(OrientationHelper.HORIZONTAL);
        mRecyclerView.addItemDecoration(
                new SpaceItemDecoration(0, 0, (int) UIUtils.getDimens(R.dimen.dimen_5), 0));
        //设置Adapter
        mAdapter = new RecommendGoodsAdapter(getActivity(), getPagerTag());

        mRecyclerView.setAdapter(mAdapter);
    }

    public void setGoodsInfo(GoodsDetailResponse.DataBean dataBean) {
        Goods goods = dataBean.getGoodsInfo();
        //详情
        mTvBrand.setText(goods.getGoodsBrand());
        mTvWeight.setText(goods.getGoodsWeight());
        mTvUnit.setText(goods.getGoodsComm());

        //可能还想买
        if (dataBean.getLiks().size() > 0) {
            mLlGoodsIntention.setVisibility(View.VISIBLE);
            mAdapter.setData(dataBean.getLiks());
        } else {
            mLlGoodsIntention.setVisibility(View.GONE);
        }
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_goods_detail_standard;
    }
}
